[C#] How to convert string encoded in windows-1250 to unicode ?
Posted
by Deveti Putnik
on Stack Overflow
See other posts from Stack Overflow
or by Deveti Putnik
Published on 2010-04-23T14:53:30Z
Indexed on
2010/04/23
15:03 UTC
Read the original article
Hit count: 539
Hi!
I am receiving from some dll (which is wrapper for some external data source) strings in Windows-1250 codepage and I would like to insert them correctly (as unicode) to table in SQL Server Database. Since particular row in database which should hold that data is of NVarchar type, I only needed to convert it in my C# code to unicode and pass it as parameter. Everything is well and nice, but I stumbled on conversion step.
I tried the following but that doesn't work:
private static String getUnicodeValue(string string2Encode) //
{
Encoding srcEncoding = Encoding.GetEncoding("Windows-1250");
UnicodeEncoding dstEncoding = new UnicodeEncoding();
byte[] srcBytes = srcEncoding.GetBytes(string2Encode);
byte[] dstBytes = dstEncoding.GetBytes(string2Encode);
return dstEncoding.GetString(dstBytes);
}
When I insert this returned string to table, I don't get correct letters like Ð, d, C, c, C or c.
Please, help! :)
© Stack Overflow or respective owner